				

function SaveSettings(fileTags,paramTags)
{
	flashpoint();
	
	printf('# saves 16 camera settings to  .jpeg .fpx ');
	printf('# to select your own, modify the ptag values');
	printf('# the ptag strings are also written to the file ');
	printf('# so this one script will also read');
	printf('# other users settings ');
	printf('# also the image file type is used: ');
	printf('# a JPEG image sets the camera into JPEG mode');
	printf('# a FPX image set the camera into FLASHPIX mode');
	printf('# smod from the image used to set the camera into off,auto,fill mode');
	printf('# so by using the "spre" tag, red-eye can be set ');

	
  writeMenu('"SaveSettings"','"EXTRA"','"SaveSettings()"');
  writeVariables();
 	printf('declare u: filecount');
 	printf('# SetFileInfo parameters ');
	printf('declare s: spath,fname');
	printf('declare u: ulength ');
	printf('declare b: bstatus' );
 	printf(' ');
 	printf('declare s: selectedFile ');
 	
 	printf('declare u: setorget,HASSOMEDATA');
 	printf('declare i: state1,state2,state3,state4');
 	printf('declare i: state5,state6,state7,state8');
 	printf('declare i: state9,state10,state11,state12');
 	printf('declare i: state13,state14,state15,state16');

	printf('declare s: ptag1,ptag2,ptag3,ptag4 ');
	printf('declare s: ptag5,ptag6,ptag7,ptag8 ');
	printf('declare s: ptag9,ptag10,ptag11,ptag12 ');
	printf('declare s: ptag13,ptag14,ptag15,ptag16 ');

	printf('declare s: sptag,sptag1,sptag2,sptag3,sptag4 ');
	printf('declare s: sptag5,sptag6,sptag7,sptag8 ');
	printf('declare s: sptag9,sptag10,sptag11,sptag12 ');
	printf('declare s: sptag13,sptag14,sptag15,sptag16 ');
	
	printf('HASSOMEDATA=12345');

	var theTags = new Array("rmod","scpn","ssdr","spre","shut","ssiz","tfmt","tsiz","xcmp","wmod","zpos");
// these follow the camera GUI
// note no "fmod" in 220 
//	var theTags = new Array("smod","scpn","ssiz","bcpn","bsiz","qbti","spre","tcpn","tsiz","tcnt","tfmt","acpd","irev","mcap","pbtr","xcmp","zpos");

	printf('<br># save these camera values ');
	printf('#replace with your own parameter tags ');
	printf(' '); 	
	for(i=1 ; i<theTags.length ; i++ ){
			st = '"'+theTags[i] + '"';
			printf("ptag"+i,' = ', st );
	
	}
 for(i=1 ; i<theTags.length ; i++ ){
 			st = '"'+ paramTags[ theTags[i] ].desc + '"';
 			printf("sptag"+i,' = ', st );
	
 	}


	
 	printf('<br>','#**** OPEN FILE ****');  
 	printf('outFile="/System/ZSets.txt"');
 	writeFileOpen();

	printf('# DEFAULT file *************');
	printf(' ');
	printf('GetFileCount(filecount) ' );
 	printf('status = GetFileInfo(0,spath,selectedFile,ulength,bstatus)  ');

	printf('OPTIONLOOP:');
	printf('DisplayClear()');
	
	printf('SetOption(0,"Save to Image ",1)' );
	printf('SetOption(1,"Save to Marked Image",0)');
	printf('SetOption(2,"Restore Settings",0)' );
	printf('SetOption(500,"Quit",0)' );
	printf('GetOption( setorget )' );
	
	printf('if setorget == 500 ');
	printf('exitscript');
	printf('end');
	
	printf('if setorget == 2 ');
	printf('goto RESTORE');
	printf('end ');
	printf(' ');
	
	printf('# choice 0 *****************************************' );
	printf('# LIST ALL AVAILABLE IMAGE FILES .JPG OR .FPX *****' );

 	printf('GetFileCount(filecount) ' );
 	printf('if filecount==0  ');  
 	printf('DisplayLine( "no files")  ');
	printf('Wait(5000)');
 	printf('goto OPTIONLOOP ');
 	printf('end	  ');
 	printf(' ');
	printf('# user likes to use marked images');
	printf('if setorget== 1');
	printf('GetMarkedImageCount(filecount) ');
	printf('end');
	printf(' ');
	
	printf(' ');
	printf('# PLACE FILES INTO OPTION MENU');
	printf('findex=0  ');
	printf(' ');
 	printf('GETANOTHERFILE:');

 	printf('status = GetFileInfo(findex,spath,fname,ulength,bstatus)  ');

	printf(' ');
	printf('# user prefers marked image method');
	printf('if setorget== 1')
	printf('GetMarkedImage(findex, spath, fname)');
	printf('end');
	
 	printf('SetOption(findex, fname ,0)  ');

	printf('#index through files (marked or unmarked)');
 	printf('if findex < filecount - 1  ');
 	printf('findex = findex + 1  ');
 	printf('goto GETANOTHERFILE  ');
 	printf('end  ');

 	printf('SetOption(1000, "Quit ",0)  ');
 	printf('GetOption(choice1)  ');
 	
 	printf('if choice1 == 1000');
 	printf('exitscript');
 	printf('end');
 	printf(' ' );
 	
 	printf('goto CONTINUE');
 	printf('RESTORE:');
 	
 	
	printf('# choice 2 *****************************************' );
	printf('# ONLY LIST IMAGE JPG,FPX FILES WITH TAG DATA *****' );
 	printf('GetFileCount(filecount) ' );
 	printf('if filecount==0  ');  
 	printf('DisplayLine( "no files")  ');
	printf('Wait(2000)');
 	printf('goto OPTIONLOOP ');
 	printf('end	  ');
	
	printf(' ');
	printf('# PLACE FILES INTO OPTION MENU');
	printf('findex=0  ');
	printf(' ');
	printf('count=0');	
 	printf('ANOTHERTAGGEDFILE:');

 	printf('status = GetFileInfo(findex,spath,fname,ulength,bstatus)  ');
	printf('# check if file contains anything ');
	printf('uvar=0');
 	printf('GetFileTag(spath,fname,"ucnr",uvar) ');

	printf('if uvar == HASSOMEDATA ');
	printf('count = count +1');
 	printf('SetOption(findex, fname ,0)  ');
	printf('end');
	printf(' ');


 	printf('if findex < filecount - 1  ');
 	printf('findex = findex + 1  ');
 	printf('goto ANOTHERTAGGEDFILE  ');
 	printf('end  ');

	printf('<br>if count == 0');
	printf('DisplayLine("NO TAGGED FILES")');
	printf('Wait(2000)');
	printf('goto OPTIONLOOP');
  	printf('end<br>');
  	
	printf('SetOption(1000, "Quit ",0)  ');
 	printf('GetOption(choice1)  ');
 	
 	printf('if choice1 == 1000');
 	printf('exitscript');
 	printf('end');
 	printf(' ' );
 	
 	printf('CONTINUE:');
 	
 	printf('# Restore or Save to this file ');
 	printf('GetFileInfo(choice1,spath,selectedFile,ulength,bstatus)  ');	
 	printf(' ');
	
 	printf('if setorget == 2')
 	printf('goto RESTORESETTINGS ');
 	printf('end')

 	printf('SAVESETTINGS:');
 	printf('# save these parameters ');

	printf(' ');
	for(i=1 ; i<theTags.length ; i++ ){	
	 	printf('status=GetCameraState(',"ptag"+i,',',"state"+i,')');
		printf('DisplayLine(',"sptag"+i,', "= "',',', "state"+i,')');
		printf('WriteLine(fd,',"sptag"+i,', "= "',',', "state"+i,')');


	}
	printf(' ');
 	
 	printf('SetUserFileTag(spath,selectedFile,"uc01",ptag1) ');
 	printf('SetUserFileTag(spath,selectedFile,"uc02",ptag2) '); 
 	printf('SetUserFileTag(spath,selectedFile,"uc03",ptag3) '); 
 	printf('SetUserFileTag(spath,selectedFile,"uc04",ptag4) '); 
 	printf('SetUserFileTag(spath,selectedFile,"uc05",ptag5) '); 
 	printf('SetUserFileTag(spath,selectedFile,"uc06",ptag6) ');
 	printf('SetUserFileTag(spath,selectedFile,"uc07",ptag7) ');
 	printf('SetUserFileTag(spath,selectedFile,"uc08",ptag8) ');
 	printf('SetUserFileTag(spath,selectedFile,"uc09",ptag9) ');
 	printf('SetUserFileTag(spath,selectedFile,"uc10",ptag10) ');
 	printf('SetUserFileTag(spath,selectedFile,"uc11",ptag11) ');
 	printf('SetUserFileTag(spath,selectedFile,"uc12",ptag12) ');
 	printf('SetUserFileTag(spath,selectedFile,"uc13",ptag13) ');
 	printf('SetUserFileTag(spath,selectedFile,"uc14",ptag14) ');
 	printf('SetUserFileTag(spath,selectedFile,"uc15",ptag15) ');
 	printf('SetUserFileTag(spath,selectedFile,"uc16",ptag16) ');
 	printf(' '); 
 	printf('DisplayLine("..saving ... ")');
 	printf(' '); 
 	printf('SetUserFileTag(spath,selectedFile,"ur01",state1) ');
 	printf('SetUserFileTag(spath,selectedFile,"ur02",state2) '); 
 	printf('SetUserFileTag(spath,selectedFile,"ur03",state3) '); 
 	printf('SetUserFileTag(spath,selectedFile,"ur04",state4) '); 
 	printf('SetUserFileTag(spath,selectedFile,"ur05",state5) '); 
 	printf('SetUserFileTag(spath,selectedFile,"ur06",state6) ');
 	printf('SetUserFileTag(spath,selectedFile,"ur07",state7) ');
 	printf('SetUserFileTag(spath,selectedFile,"ur08",state8) ');
 	printf('SetUserFileTag(spath,selectedFile,"ur09",state9) ');
 	printf('SetUserFileTag(spath,selectedFile,"ur10",state10) ');
 	printf('SetUserFileTag(spath,selectedFile,"ur11",state11) ');
 	printf('SetUserFileTag(spath,selectedFile,"ur12",state12) ');
 	printf('SetUserFileTag(spath,selectedFile,"ur13",state13) ');
 	printf('SetUserFileTag(spath,selectedFile,"ur14",state14) ');
 	printf('SetUserFileTag(spath,selectedFile,"ur15",state15) ');
 	printf('SetUserFileTag(spath,selectedFile,"ur16",state16) ');
 	
 	printf('SetUserFileTag(spath,selectedFile,"ucnr",HASSOMEDATA) '); 	
	printf('goto OPTIONLOOP');
	
	printf('RESTORESETTINGS: ');
	printf('# restore these parameters ');
 	
 	printf('GetFileTag(spath,selectedFile,"ur01",state1) ');
 	printf('GetFileTag(spath,selectedFile,"ur02",state2) '); 
 	printf('GetFileTag(spath,selectedFile,"ur03",state3) '); 
 	printf('GetFileTag(spath,selectedFile,"ur04",state4) '); 
 	printf('GetFileTag(spath,selectedFile,"ur05",state5) '); 
 	printf('GetFileTag(spath,selectedFile,"ur06",state6) ');
 	printf('GetFileTag(spath,selectedFile,"ur07",state7) ');
 	printf('GetFileTag(spath,selectedFile,"ur08",state8) ');
 	printf('GetFileTag(spath,selectedFile,"ur09",state9) ');
 	printf('GetFileTag(spath,selectedFile,"ur10",state10) ');
 	printf('GetFileTag(spath,selectedFile,"ur11",state11) ');
 	printf('GetFileTag(spath,selectedFile,"ur12",state12) ');
 	printf('GetFileTag(spath,selectedFile,"ur13",state13) ');
 	printf('GetFileTag(spath,selectedFile,"ur14",state14) ');
 	printf('GetFileTag(spath,selectedFile,"ur15",state15) ');
 	printf('GetFileTag(spath,selectedFile,"ur16",state16) ');

	printf('DisplayLine("...restoring ... ")');
	
 	printf('# get actual tag  value ');
 	printf('# allows compatibility between different parameter sets ');
 	printf('GetFileTag(spath,selectedFile,"uc01",ptag1) ');
 	printf('GetFileTag(spath,selectedFile,"uc02",ptag2) '); 
 	printf('GetFileTag(spath,selectedFile,"uc03",ptag3) '); 
 	printf('GetFileTag(spath,selectedFile,"uc04",ptag4) '); 
 	printf('GetFileTag(spath,selectedFile,"uc05",ptag5) '); 
 	printf('GetFileTag(spath,selectedFile,"uc06",ptag6) ');
 	printf('GetFileTag(spath,selectedFile,"uc07",ptag7) ');
 	printf('GetFileTag(spath,selectedFile,"uc08",ptag8) ');
 	printf('GetFileTag(spath,selectedFile,"uc09",ptag9) ');
 	printf('GetFileTag(spath,selectedFile,"uc10",ptag10) ');
 	printf('GetFileTag(spath,selectedFile,"uc11",ptag11) ');
 	printf('GetFileTag(spath,selectedFile,"uc12",ptag12) ');
 	printf('GetFileTag(spath,selectedFile,"uc13",ptag13) ');
 	printf('GetFileTag(spath,selectedFile,"uc14",ptag14) ');
 	printf('GetFileTag(spath,selectedFile,"uc15",ptag15) ');
 	printf('GetFileTag(spath,selectedFile,"uc16",ptag16) ');
 	
	printf(' ');
 
 
	// get some information from the file itself
	printf('# some information from the image itself ');
 	printf('GetFileTag(spath,selectedFile,"imcn",svar) ');
 	printf('param="flty"');
	printf('if svar!="JPEG"');
 	printf('uvar=0x46505820'); 	
 	printf('SetCameraState(param,uvar)');
  	printf('DisplayLine("FLASHPIX" )');
  	printf('end');
	printf(' ');
 	printf('if svar== "JPEG"');
 	printf('uvar=0x4a504547');
 	printf('status=SetCameraState(param,uvar)');
 	printf('DisplayLine("JPEG " )');
 	printf('end');

 	printf(' ');
 	printf('GetFileTag(spath,selectedFile,"smod",uvar) ');
	printf('if uvar==1');
	printf('DisplayLine("STROBE OFF")');
	printf('end');
	printf('if uvar==2');
	printf('DisplayLine("STROBE AUTO")');
	printf('end');
	printf('if uvar==3');
	printf('DisplayLine("STROBE FILL")');
	printf('end');	
 	printf('SetCameraState("smod",uvar) ');
	printf(' ');

 	printf(' ');
 	printf('uvar=0');
 	printf('GetFileTag(spath,selectedFile,"fmtd",uvar) ');
	printf('if uvar==1');
	printf('DisplayLine("MULTI-SPOT FOCUS")');
	printf('end');
	printf('if uvar==2');
	printf('DisplayLine("SINGLE-SPOT FOCUS")');
	printf('end');
 	printf('SetCameraState("fmtd",uvar) ');

 	printf(' ');
 	printf('uvar=0');
 	printf('GetFileTag(spath,selectedFile,"fmod",uvar) ');
	printf('if uvar==1');
	printf('DisplayLine("AUTO FOCUS")');
	printf('end');
	printf('if uvar==3');
	printf('DisplayLine("MANUAL FOCUS")');
	printf('end');
 	printf('SetCameraState("fmod",uvar) ');
 	printf(' ');
	
	
	for(i=1 ; i<theTags.length ; i++ ){	
	 	printf('status=SetCameraState(',"ptag"+i,',',"state"+i,')');
		printf('DisplayLine(',"sptag"+i,',','"= "',", state"+i,')');
		printf('WriteLine(fd,',"sptag"+i,',','"= "',", state"+i,')');
		printf(' ')
	}
	printf(' ');

 	printf('Wait(5000)');
	printf('goto OPTIONLOOP');

	
	writeFileClose();
	printf('exitscript');

}
						
						
